package cn.hairui.blog.dao;

import cn.hairui.blog.entity.Album;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 相册表 Mapper 接口
 * </p>
 *
 * @author laoganbu
 * @since 2020-04-15
 */
@Mapper
public interface AlbumMapper extends BaseMapper<Album> {

    @Select("SELECT\n" +
            "    T1.ID       AS id,\n" +
            "    T1.NAME     AS name,\n" +
            "    T1.SHOW_IMG AS showImg,\n" +
            "    CASE\n" +
            "        WHEN T1.SHOW_FLAG='Y'\n" +
            "        THEN 'checked'\n" +
            "        ELSE ''\n" +
            "    END         AS showFlag,\n" +
            "    CREATE_TIME AS createTime,\n" +
            "    (\n" +
            "        SELECT\n" +
            "            T2.NICKNAME\n" +
            "        FROM\n" +
            "            USER T2\n" +
            "        WHERE\n" +
            "            T1.CREATOR=T2.ACCOUNT) AS creator,\n" +
            "    (\n" +
            "        SELECT\n" +
            "            COUNT(1)\n" +
            "        FROM\n" +
            "            ALBUMIMG T3\n" +
            "        WHERE\n" +
            "            T3.ALBUM_ID=T1.ID) AS imgNum,\n" +
            "    T1.LOCATION                AS location\n" +
            "FROM\n" +
            "    ALBUM T1\n" +
            "ORDER BY\n" +
            "    T1.ID ASC")
    List<Map> listMgr();

    @Select("SELECT COUNT(1) FROM ALBUMIMG WHERE ALBUM_ID=#{albumId}")
    int getImagesCount(int albumId);
}
